import java.util.Arrays;

class Person {
    public String name;

    public int age;

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }
}

public class Test2 {
    public static void main(String[] args) {
        String str = "hello";
        String ret = str.substring(1);//从1下标开始截取
        System.out.println(ret);
        System.out.println("===============");
        String ret2 = str.substring(1,3);
        System.out.println(ret2);   
    }
    public static void main5(String[] args) {
        String str = "hello world hello bit";
        String[] ret = str.split(" ",3);//分隔为3份
        //String[] ret = str.split(" ");//根据指定的字符去分隔字符串
        for(int i = 0; i < ret.length; i++) {
            System.out.println(ret[i]);
        }
        System.out.println("=============");
        String str2 = "172.16.2.2";
        String[] ret2 = str2.split(".");//需要加上分隔符
        for(int i = 0; i < ret2.length; i++) {
            System.out.println(ret2[i]);
        }
    }
    public static void main4(String[] args) {
        String str1 = "abcabcabcabcabcdef";
        String ret = str1.replaceFirst("ab","oooo");//将第一个ab替换为oooo
        System.out.println(ret);
        System.out.println("================");
        String ret2 = str1.replaceAll("ab","oo");
        System.out.println(ret2);

        String ret3 = str1.replace("ab","oo");
        System.out.println(ret3);//与replaceAll用法相同
        String ret4 = str1.replace('a','v');
        System.out.println(ret4);


    }
    public static void main3(String[] args) {
        String s1 = String.valueOf(1234);
        System.out.println(s1);

        String s2 = String.valueOf(new Person("wangwu",15));
        System.out.println(s2);

        System.out.println("==============");
        int data1 = Integer.valueOf("123");
        System.out.println(data1);

        String str = "abc";
        System.out.println(str.toUpperCase());//转化为大写
        //并不是在原来的基础上进行修改的，
        String str1 = "ABCDE";
        System.out.println(str1.toLowerCase());//大写转化为小写

        System.out.println("============");
        String str2 = "hellobit";
        char[] array = str2.toCharArray();
        System.out.println(Arrays.toString(array));//将字符串转化为数组

        System.out.println("==============");
        String s5 = String.format("%d-%d-%d",15,20,30);
        System.out.println(s5);
    }

    public static void main2(String[] args) {
        String str1 = "hello";
        char ch = str1.charAt(1);//我们可以拿到下标为1的字符
        System.out.println(ch);
        System.out.println(str1.indexOf('l'));//寻找l第一次出现的位置
        System.out.println(str1.indexOf('l', 3));//从下标为3位置查找l第一次出现的位置
        System.out.println(str1.indexOf("ll"));//寻找某个字符串第一次出现的位置
        System.out.println("====================");
        str1.lastIndexOf('l');//从后往前查找这个字符出现的位置,但是下标依然是从0开始从左往右
        str1.lastIndexOf('l',4);//从第四个位置从后往前查找l这个字符
    }
    public static void main1(String[] args) {
        String str1 = "hello";
        String str2 = new String("hello");//上面是对这个的简写
        char[] chars = {'a','b','c','d'};

        String str3 = new String(chars);
        System.out.println(str3);
        System.out.println(str1);
        System.out.println(str2);
        System.out.println(str1.length());
        System.out.println(str2.length());//求字符串长度
        System.out.println("===================");
        String str4 = "";
        System.out.println(str4.isEmpty());
        System.out.println(str1 == str2);//这里比较的是地址  这里输出的是false
        System.out.println(str1.equals(str2));//这里比较的是内容
        System.out.println("===================");
        String str5 = "abc";
        String str6 = "abc";
        System.out.println(str5 == str6);//这里输出的是true
        //这个情况下直接拿到的是同一份地址
        System.out.println("============");
        //比较大小
        String str7 = "abcdef";
        String str8 = "abcd";
        System.out.println(str7.compareTo(str8));
        //str7>str8返回正数 相等返回0 小于返回负数

        //忽略大小写比较
        String str10 = "abc";
        String str11 = "abC";
        System.out.println(str11.compareToIgnoreCase(str10));

    }
}
